package com.weixin.paleituo.item;

import android.support.annotation.NonNull;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.baozi.treerecyclerview.base.ViewHolder;
import com.baozi.treerecyclerview.item.TreeItem;
import com.baozi.treerecyclerview.item.TreeItemGroup;
import com.weixin.paleituo.R;
import com.weixin.paleituo.application.BaseApplication;
import com.weixin.paleituo.bean.GoodsListBeans;
import com.weixin.paleituo.util.UIUtils;

/**
 * Created by a123 on 2018/6/5.
 */

public class CartItem extends TreeItem<GoodsListBeans> {

    @Override
    public int getLayoutId() {
        return R.layout.item_after_sale_request_child;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder viewHolder) {
        TreeItemGroup parentItem = getParentItem();
        if (parentItem instanceof CartGroupItem) {
         //   viewHolder.setChecked(R.id.cb_ischeck, ((CartGroupItem) parentItem).getSelectItems().contains(this));
        }
        GoodsListBeans data = getData();
        ImageView ivGood= viewHolder.getImageView(R.id.iv_icon_item_sfter_sale_request_child);
        TextView tvgoodName = viewHolder.getTextView(R.id.tv_name_item_sfter_sale_request_child);
        TextView tvNumber = viewHolder.getTextView(R.id.tv_number_item_sfter_sale_request_child);
        TextView tvState = viewHolder.getTextView(R.id.tv_state_item_sfter_sale_request_child);
      ImageView ivMore=  viewHolder.getImageView(R.id.iv_more_item_sfter_sale_request_child);
       TextView tvRequest= viewHolder.getTextView(R.id.tv_request_item_sfter_sale_request_child);
        //（服务状态，，3服务单已过期）

        String listUrl = data.getListUrl();

        UIUtils.loadImageView(BaseApplication.getContext(),listUrl,ivGood);
        String goodsName = data.getGoodsName();

        tvgoodName.setText(goodsName);

        int goodsSalenum = data.getGoodsSalenum();
        tvNumber.setText("数量："+goodsSalenum);



        int serviceStatus = data.getServiceStatus();


        if (serviceStatus==1){
            //1-未提交服务单
            tvState.setVisibility(View.INVISIBLE);
            ivMore.setVisibility(View.INVISIBLE);
            tvRequest.setVisibility(View.VISIBLE);
            tvRequest.setBackgroundResource(R.drawable.eable_after_sale_shape);
            tvRequest.setTextColor(UIUtils.getColor(R.color.c_29CE7E));



        }else if (serviceStatus==2){
            //2-已提交服务单
            tvRequest.setVisibility(View.INVISIBLE);
            tvState.setVisibility(View.VISIBLE);
            ivMore.setVisibility(View.VISIBLE);
            tvState.setText("该商品已申请售后");





        }else if (serviceStatus==3){
            //，3服务单已过期
            tvRequest.setVisibility(View.INVISIBLE);
            tvState.setVisibility(View.VISIBLE);
            ivMore.setVisibility(View.INVISIBLE);
            tvState.setText("该商品已超过售后期");
            tvRequest.setBackgroundResource(R.drawable.diseable_after_sale_shape);
            tvRequest.setTextColor(UIUtils.getColor(R.color.c_e1e0e5));

        }



    }

    @Override
    public void onClick(ViewHolder viewHolder) {
        super.onClick(viewHolder);
        getItemManager().notifyDataChanged();
    }
}
